from docutils import nodes
from sphinx.util.docutils import SphinxDirective

class DoxygenPageDirective(SphinxDirective):
    required_arguments = 1
    
    def run(self):
        page_type = self.arguments[0].lower()
        page_mapping = {
            'namespaces': 'namespaces.html',
            'classes': 'annotated.html',
            'files': 'files.html',
            'modules': 'modules.html'
        }
        
        if page_type not in page_mapping:
            return [self.state.document.reporter.warning(
                f'Unknown page type: {page_type}')]
            
        url = f'/doxygen/html/{page_mapping[page_type]}'
        paragraph = nodes.paragraph()
        paragraph += nodes.reference('', page_type.title(), refuri=url)
        return [paragraph]

def setup(app):
    app.add_directive('doxygenpage', DoxygenPageDirective)
    return {
        'version': '1.0',
        'parallel_read_safe': True,
        'parallel_write_safe': True,
    } 